home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / print / p1123mz4.zip / HEXAGON.CPP < prev    next >
Text File  |  1994-03-02  |  5KB  |  150 lines

  1. //
  2. //       This program will generate a three dimensional maze on a Panasonic 1123
  3. //  printer.  A different random number seed will produce a different maze.
  4. //
  5. //       Written by James L. Dean
  6. //                  406 40th Street
  7. //                  New Orleans, LA 70124-1532
  8. //
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <math.h>
  12. #include <stdlib.h>
  13. #include <conio.h>
  14. #include <time.h>
  15. #include <iostream.h>
  16. #include "oracle.h"
  17. #include "cell.h"
  18. #include "titillat.h"
  19. #include "hexmaze.h"
  20. #include "plot3d.h"
  21. #include "x1123x3d.h"
  22.  
  23. #ifndef TRUE
  24. #define TRUE -1
  25. #endif
  26. #ifndef FALSE
  27. #define FALSE 0
  28. #endif
  29.  
  30. // maze constants
  31. #define PIXELS_PER_ROOM   80
  32. #define RESOLUTION         4  // larger values takes more time (and virtual
  33.                               // memory) but produce a better image
  34.  
  35. static int    external_to_plot(double,double);
  36. static double f(double,double);
  37.        int    main(int,char **);
  38. static int    red(double,double);
  39.  
  40. extern unsigned _stklen=0x8000;
  41.        maze     *maze_ptr;
  42.  
  43. int main(
  44.   int argc,
  45.   char *argv[])
  46.     {
  47.       static   double   bias;
  48.       static   int      fatal_error;
  49.       static   int      num_columns;
  50.       static   int      num_rows;
  51.       static   double   light_x;
  52.       static   double   light_y;
  53.       static   double   light_z;
  54.       static   double   rotation;
  55.                time_t   start_time;
  56.                time_t   stop_time;
  57.       static   double   tilt;
  58.       static   x1123x3d *x1123x3d_ptr;
  59.  
  60.       fatal_error=FALSE;
  61.       if ((argc == 2) || ((argc == 3) && (atof(argv[2]) > 0.0)))
  62.         {
  63.           time(&start_time);
  64.           if (argc == 2)
  65.             bias=0.3;
  66.           else
  67.             bias=atof(argv[2]);
  68.           x1123x3d_ptr=new x1123x3d();
  69.           num_columns=(2*(x1123x3d_ptr->num_x_pixels()))/(3*PIXELS_PER_ROOM)-1;
  70.           num_columns=2*num_columns+1;
  71.           num_rows=(int) (((2.0/sqrt(3.0))
  72.            *(x1123x3d_ptr->aspect_ratio())
  73.            *((double) (x1123x3d_ptr->num_y_pixels())))
  74.            /((double) PIXELS_PER_ROOM));
  75.           maze_ptr=new maze(num_rows,num_columns,RESOLUTION,argv[1]);
  76.           if (maze_ptr->constructed())
  77.             {
  78.               rotation=(double) 0.0;
  79.               tilt=(double) 30.0;
  80.               light_x=(double) 1.5;
  81.               light_y=(double) -1.0;
  82.               light_z=(double) 2.6;
  83.               if (x1123x3d_ptr->prepare_plot(f,
  84.                maze_ptr->x_min(),maze_ptr->x_max(),
  85.                maze_ptr->y_min(),maze_ptr->y_max(),external_to_plot,red,
  86.                maze_ptr->num_x_divisions(),maze_ptr->num_y_divisions(),
  87.                rotation,tilt,light_x,light_y,light_z))
  88.                 if (x1123x3d_ptr->plot("HEXAGON.MAZ",FALSE,TRUE,bias))
  89.                   if (x1123x3d_ptr->plot("HEXAGON.SOL",TRUE,TRUE,bias))
  90.                     {
  91.                       time(&stop_time);
  92.                       cout << '\n' << "     It took " << stop_time-start_time
  93.                        << " seconds to generate the maze and its solution."
  94.                        << '\n' << '\n'
  95.                        << "     If LPT1: is your Panasonic 1123, "
  96.                        << "\"COPY /B HEXAGON.MAZ LPT1:\"" << '\n'
  97.                        << "and \"COPY /B HEXAGON.SOL LPT1:\"." << '\n';
  98.                     }
  99.                   else
  100.                     fatal_error=TRUE;
  101.                 else
  102.                   fatal_error=TRUE;
  103.               else
  104.                 fatal_error=TRUE;
  105.             }
  106.           else 
  107.             fatal_error=TRUE;
  108.           delete maze_ptr;
  109.           delete x1123x3d_ptr;
  110.         }
  111.       else
  112.         cout << '\n' << "     This program will generate a three dimensional "
  113.          << "maze suitable for " << '\n' << "printing on a Panasonic 1123 "
  114.          << "printer.  It writes the maze to the file" << '\n'
  115.          << "\"HEXAGON.MAZ\" and the solution to \"HEXAGON.SOL\"." << '\n' 
  116.          << '\n'
  117.          << "     If LPT1: is your Panasonic 1123, \"COPY /B HEXAGON.MAZ "
  118.          << "LPT1:\" to" << '\n' << "print the maze and \"COPY /B HEXAGON.SOL "
  119.          << "LPT1:\" to print the solution." << '\n' << '\n'
  120.          << "     Usage:  HEXAGON <random number seed> [<bias>]" << '\n' << '\n'
  121.          << "       A different <random number seed> will produce a different "
  122.          << "maze." << '\n' << '\n' << "       <bias> adjusts the contrast.  "
  123.          << "It defaults to 0.3 for a new ribbon." << '\n'
  124.          << "       0.5 or higher should be used for a worn ribbon." << '\n'
  125.          << '\n' << "     Example:  HEXAGON 61743076 0.5" << '\n';
  126.       return(fatal_error);
  127.     }
  128.  
  129. static int external_to_plot(
  130.   double x,
  131.   double y)
  132.     {
  133.        return maze_ptr->external_to_maze(x,y);
  134.     }
  135.  
  136. static int red(
  137.   double x,
  138.   double y)
  139.     {
  140.        return maze_ptr->part_of_solution(x,y);
  141.     }
  142.  
  143. static double f(
  144.   double x,
  145.   double y)
  146.     {
  147.        return maze_ptr->f(x,y);
  148.     }
  149. 
  150.